/* 
 * Copyright [2017] [Alex/LiBo(libo2dev.aliyun.com/alex.link@foxmail.com)]
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.hyts.bmsp.record;

import java.util.List;
import java.util.Map;

import org.apache.commons.collections.CollectionUtils;

import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;

/**  
 * @Title JdbcDaoSupport.java  
 * @Package com.hyts.bmsp.dao  
 * @Description jdbc数据库连接方式的支持操作核心数据库操作类  
 * @author LiBo/Alex  
 * @date 2017年12月24日  
 * @version V1.0  
 */
public class JdbcDaoSupport extends RecordDaoSupport<BaseModel,BaseQuery>{

	/* (非 Javadoc)  
	 * <p>Title: query</p>  
	 * <p>Description: </p>  
	 * @param sql
	 * @return  
	 * @see com.hyts.bmsp.record.AbstractQueryDao#query(java.lang.String)  
	 */  
	@Override
	public List<Record> query(String sql) {
		return Db.query(sql);
	}

	/* (非 Javadoc)  
	 * <p>Title: query</p>  
	 * <p>Description: </p>  
	 * @param sql
	 * @param params
	 * @return  
	 * @see com.hyts.bmsp.record.AbstractQueryDao#query(java.lang.String, java.util.Map)  
	 */  
	@Override
	public List<Record> query(String sql, Object... params) {
		return Db.query(sql, params);
	}

	/* (非 Javadoc)  
	 * <p>Title: load</p>  
	 * <p>Description: </p>  
	 * @param sql
	 * @return  
	 * @see com.hyts.bmsp.record.AbstractQueryDao#load(java.lang.String)  
	 */  
	@Override
	public Record load(String sql) {
		List<Record> recordList = Db.query(sql);
		if(CollectionUtils.isNotEmpty(recordList) && recordList.size() >= 1){
			return recordList.get(0);
		}
		return null;
	}

	/* (非 Javadoc)  
	 * <p>Title: load</p>  
	 * <p>Description: </p>  
	 * @param sql
	 * @param id
	 * @return  
	 * @see com.hyts.bmsp.record.AbstractQueryDao#load(java.lang.String, java.lang.Object)  
	 */  
	@Override
	public  Record load(String sql, Object id) {
		List<Record> recordList = Db.query(sql,id);
		if(CollectionUtils.isNotEmpty(recordList) && recordList.size() >= 1){
			return recordList.get(0);
		}
		return null;
	}

	/* (非 Javadoc)  
	 * <p>Title: load</p>  
	 * <p>Description: </p>  
	 * @param sql
	 * @param params
	 * @return  
	 * @see com.hyts.bmsp.record.AbstractQueryDao#load(java.lang.String, java.util.Map)  
	 */  
	@Override
	public Record load(String sql, Object... params) {
		List<Record> recordList = Db.query(sql,params);
		if(CollectionUtils.isNotEmpty(recordList) && recordList.size() >= 1){
			return recordList.get(0);
		}
		return null;
	}
	
	
}
